<?php
   $index = $_GET['index']; // 第一页 1
   $len = $_GET['len'];  // 20 
   $index = ($index - 1) * $len;
//    echo $index;
$con = mysqli_connect('localhost','root','123456','goodslist');

// $sql1 = "SELECT * FROM `goods`  ";
// 获取数据从 idx 索引开始 ，leng 多少条
$sql1 = "SELECT * FROM `goods` LIMIT $index,$len";
$res1 = mysqli_query($con,$sql1);
if(!$res1){
    die('error:数据库的链接错误' . mysqli_error($con));
}
$arr = array();
$row1 = mysqli_fetch_assoc($res1);
while($row1){
    array_push($arr,$row1);
    $row1 = mysqli_fetch_assoc($res1);
}
// 转化为json数据类型
// $arr = json_encode($arr,JSON_UNESCAPED_UNICODE);
// print_r($arr);   

// 获取数据库中的总数
$sql2="SELECT COUNT(*) `count` FROM `goods`";
$res2 = mysqli_query($con,$sql2);
if(!$res2){
    die('error:数据库的链接错误' . mysqli_error($con));
}
$count = mysqli_fetch_assoc($res2);

$data = array('status'=>200,'total'=>$count['count'],'list'=>$arr);
echo json_encode($data,JSON_UNESCAPED_UNICODE);
?>